import java.util.Iterator;
import java.util.List;

/**
 * Communicates with the Index to get the necessary
 * data for each QUIRK command
 * 
 * @author Andrew Bernard
 */
public class IndexManager {   
  private Index index = null; 
  
  /**
   * Constructor. Creates a new instance of Index
   */
  public IndexManager() {
    index = new Index();
  }
  
  public void statsCommand() {
    StringBuffer stats = new StringBuffer();
    stats.append("\n-------- Corpus Files --------");
    
    List dataHeaderList = index.getDataHeaderList();
    Iterator itr = dataHeaderList.iterator();
    while(itr.hasNext()) {
      Index.DataHeader dataHeader = (Index.DataHeader)itr.next();
      stats.append("\n\nFile name: "+dataHeader.fileName)
           .append("\nCharacters: "+dataHeader.charsInFile)
           .append("\nWords: "+dataHeader.wordsInFile)
           .append("\nLines: "+dataHeader.linesInFile);
    }
    
    Index.Summary summary = index.getSummary();
    stats.append("\n\n-------- Corpus Summary --------\n")
         .append("Characters: " + summary.charsInCorpus + "\n")
         .append("Words: " + summary.wordsInCorpus + "\n")
         .append("Lines: " + summary.linesInCorpus + "\n")
         .append("Files: " + summary.filesInCorpus);
    outln(stats.toString());
  }
  
  public void indexCommand() {
    outln("INDEX? What index? Look it up yourself :p");
  }
  
  public void queryCommand(String query) {
    outln(query + " ... HUH? You want me to do what? ... You're kidding right!");
  }
  
  public void refineCommand(String refined) {
    outln(refined + " ... dude, make up your mind!");
  }
  
  public void showCommand() {
    outln("SHOW ME THE MONEY!!!");
  }
  
  public void nextCommand() {
    outln("NEXT project, I'm hiring a PM");
  }
  
  /** This is here because I'm lazy ;) */
  private static void outln(String text) {
    System.out.println(text);
  }
}
